import time
from selenium import webdriver
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.common.by import By
from datetime import datetime

options = webdriver.ChromeOptions()

options.page_load_strategy = "normal"  # 等待页面完全加载
# 创建浏览器驱动对象
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(5)
action = ActionChains(driver)
url = r"https://cn.bing.com/"
driver.get(url)
driver.find_element(By.XPATH, "//input[@id='sb_form_q']").send_keys("日常聊天室", Keys.ENTER)
time.sleep(3)
driver.find_element(By.XPATH, "//a[@target='_blank']/strong[text()='日常聊天室']").click()

driver.close()
# 切换浏览器窗口 权柄
driver.switch_to.window(driver.window_handles[0])

driver.find_element(By.LINK_TEXT, "进入").click()

time.sleep(2)
name = driver.find_element(By.XPATH, "//input[@placeholder='请输入昵称']")
name.clear()
name.send_keys("虫虫")
driver.find_element(By.XPATH, "//button[text()='进入大厅']").click()
driver.find_element(By.XPATH, "//p[text()='二次元孵化中心']").click()
time.sleep(3)
# 获取当前日期和时间
current_datetime = datetime.now()
# 格式化为字符串
formatted_time = current_datetime.strftime("%Y-%m-%d %H:%M:%S")
driver.find_element(By.XPATH, "//textarea[@class='rc-textarea']").send_keys("北京时间:" + formatted_time, Keys.ENTER)
driver.close()
driver.quit()
